let extension = {
    components: { //动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader: () =>
            import("./Sys_User/Sys_UserGridHeader.vue"),
        gridBody: '',
        gridFooter: '',
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: '',
        modelBody: '',
        modelFooter: ''
    },
    text: "",
    buttons: [], //扩展的按钮
    methods: { //事件扩展
        onInit() {
            this.boxOptions.height = 530;
            this.columns.push({
                title: '操作',
                fixed: 'right',
                width: 140,
                render: (h, { row, column, index }) => {
                    return h(
                        "div", { style: {} }, [
                        h(
                            "a", {
                            props: {},
                            style: {},
                            on: {
                                click: (e) => {
                                    e.stopPropagation()
                                    this.$refs.gridHeader.open(row);
                                }
                            }
                        },
                            "修改密码"
                        ),
                        h(
                            "Dropdown", {
                            props: {},
                            style: {
                                "margin-left": "10px"
                            },
                            on: {
                                'on-click': (name) => {
                                    if (name == 'add') {
                                        this.add();
                                    } else if (name == 'update') {
                                        this.linkData(row);
                                    } else {
                                        this.$Message.info(name);
                                    }
                                }
                            }
                        }, [h('a', {}, ['更多', h('Icon', { props: { type: 'ios-arrow-down' } })]),
                        h('DropdownMenu', { slot: "list" }, [h('DropdownItem', { props: { name: 'update' } }, '编辑'),
                        h('DropdownItem', { props: { name: 'add' } }, '新建'),
                        ])
                        ]
                        )
                    ])
                }
            })
        },
        rowClick({ row, column, event }) { //查询界面table点击行选中当前行
            this.$refs.table.$refs.table.toggleRowSelection(row);
            return true;
        },
        getOption(field) {
            let option;
            this.editFormOptions.forEach(x => {
                x.forEach(item => {
                    if (item.field == field) {
                        option = item;
                    }
                })
            })
            return option;
        },
        onInited() { },
        addAfter(result) { //用户新建后，显示随机生成的密码
            if (!result.status) {
                return true;
            }
            //显示新建用户的密码
            //2020.08.28优化新建成后提示方式
            this.$confirm(result.message, '新建用户成功', {
                confirmButtonText: '确定',
                type: 'success',
                center: true
            }).then(() => { })

            this.boxModel = false;
            this.refresh();
            return false;
        },
        modelOpenAfter(row) {
            let userTypeSupp = this.getOption("userTypeSupp");
            let userTypeDist = this.getOption("userTypeDist");
            let userTypeDataExpress = this.getOption("userTypeDataExpress");
            console.log(row,"row")
             if(row!=undefined){
                if(row.userType=='1'){
                    userTypeSupp.hidden = false;
                    userTypeSupp.required = true;
                    userTypeDist.required = false;
                    userTypeDist.hidden = true;
                    userTypeDataExpress.required = false;
                    userTypeDataExpress.hidden = true;
                }else if(row.userType=='2'){
                    userTypeSupp.hidden = true;
                    userTypeSupp.required = false;
                    userTypeDist.required = true;
                    userTypeDist.hidden = false;
                    userTypeDataExpress.required = false;
                    userTypeDataExpress.hidden = true;
                }else if(row.userType=='3'){
                  userTypeSupp.hidden = true;
                  userTypeSupp.required = false;
                  userTypeDist.required = true;
                  userTypeDist.hidden = false;
                  userTypeDataExpress.required = true;
                  userTypeDataExpress.hidden = false;
              } else {
                    userTypeSupp.hidden = true;
                    userTypeSupp.required = false;
                    userTypeDist.required = false;
                    userTypeDist.hidden = true;
                    userTypeDataExpress.required = false;
                    userTypeDataExpress.hidden = true;
                }
            }

            //点击弹出框后，如果是编辑状态，禁止编辑用户名，如果新建状态，将用户名字段设置为可编辑
            let isEDIT = this.currentAction == this.const.EDIT;
            this.editFormOptions.forEach(item => {
                item.forEach(x => {
                    if (x.field == "UserName") {
                        this.$set(x, "disabled", isEDIT)

                    }
                    if (x.field == "userType") {
                        x.onChange = (val, option) => {
                            if (val == 1) {
                                userTypeSupp.hidden = false;
                                userTypeSupp.required = true;
                                userTypeDist.required = false;
                                userTypeDist.hidden = true;
                                userTypeDataExpress.required = false;
                                userTypeDataExpress.hidden = true;
                            } else if (val == 2) {
                                userTypeSupp.hidden = true;
                                userTypeSupp.required = false;
                                userTypeDist.required = true;
                                userTypeDist.hidden = false;
                                userTypeDataExpress.required = false;
                                userTypeDataExpress.hidden = true;
                            } else if (val == 3) {
                              userTypeSupp.hidden = true;
                              userTypeSupp.required = false;
                              userTypeDist.required = false;
                              userTypeDist.hidden = true;
                              userTypeDataExpress.required = true;
                              userTypeDataExpress.hidden = false;
                            } else {
                                userTypeSupp.hidden = true;
                                userTypeSupp.required = false;
                                userTypeDist.required = false;
                                userTypeDist.hidden = true;
                                userTypeDataExpress.required = false;
                                userTypeDataExpress.hidden = true;
                            }
                        }
                    }
                })
                //不是新建，性别默认值设置为男
                if (!isEDIT) {
                    this.editFormFileds.Gender = "1";


                }
            })
        },
        addBefore (formData) { //新建保存前formData为对象，包括明细表
            return this.veriFromTable(formData)
          },
        updateBefore (formData) { //编辑保存前formData为对象，包括明细表、删除行的Id
            return this.veriFromTable(formData)
        },
        // 保存前编辑
        veriFromTable (formData) {
            let list = this.getOption('Role_Id')
            list.data.forEach((item) => {
                if(item.key === this.editFormFileds.Role_Id) {
                    formData.mainData.RoleName = item.value
                }
            })
            return true
        },
    }
};
export default extension;
